<?php

namespace backend\jobs;

/**
 * Class DownloadJob.
 */
class DownloadJob extends \yii\base\BaseObject implements \yii\queue\RetryableJobInterface
{
    public $url;

    public $file;

    /**
     * @inheritdoc
     */
    public function execute($queue)
    {

        file_put_contents($this->file, file_get_contents($this->url));

    }

    /**
     * @inheritdoc
     */
    public function getTtr()
    {
        return 60;
    }

    /**
     * @inheritdoc
     */
    public function canRetry($attempt, $error)
    {
        return ($attempt < 5) && ($error);

    }
}
